// test_struct.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <string>
#include <vector>

struct UserStatistics
{
	UserStatistics()
		: Points(0)
	{
	}

	std::string User;
	unsigned int Points;
};

struct QuizStatistics
{
	QuizStatistics()
		: processedQuestions(0)
		, correctAnswers(0)
	{
	}

	~QuizStatistics()
	{
		for (std::vector<UserStatistics*>::iterator it = userStats.begin(), it_end = userStats.end(); it != it_end; ++it)
			delete *it;
	}

	QuizStatistics(const QuizStatistics& obj)
	{
		for (std::vector<UserStatistics*>::const_iterator it = obj.userStats.begin(), it_end = obj.userStats.end(); it != it_end; ++it)
		{
			UserStatistics* stat = new UserStatistics;
			stat->User = (*it)->User;
			stat->Points = (*it)->Points;
			userStats.push_back(stat);
		}
		processedQuestions = obj.processedQuestions;
		correctAnswers = obj.correctAnswers;
	}

	QuizStatistics& operator=(const QuizStatistics& obj)
	{
		if (&obj == this)
			return *this;

		for (std::vector<UserStatistics*>::const_iterator it = obj.userStats.begin(), it_end = obj.userStats.end(); it != it_end; ++it)
		{
			UserStatistics* stat = new UserStatistics;
			stat->User = (*it)->User;
			stat->Points = (*it)->Points;
			this->userStats.push_back(stat);
		}
		this->processedQuestions = obj.processedQuestions;
		this->correctAnswers = obj.correctAnswers;

		return *this;
	}

	std::vector<UserStatistics*> userStats;
	unsigned int processedQuestions;
	unsigned int correctAnswers;
};

class TestClass
{
public:
	TestClass()
	{
		UserStatistics stat;
		stat.User = "first";
		stat.Points = 1;
		m_UserInfo.push_back(stat);

		stat.User = "second";
		stat.Points = 2;
		m_UserInfo.push_back(stat);
	}

	void Fill(std::vector<UserStatistics*>& info)
	{
		for (std::vector<UserStatistics>::const_iterator it = m_UserInfo.begin(), it_end = m_UserInfo.end(); it != it_end; ++it)
		{
			UserStatistics* stat = new UserStatistics();
			stat->User = it->User;
			stat->Points = it->Points;
			info.push_back(stat);
		}
	}

private:
	std::vector<UserStatistics> m_UserInfo;
};



int _tmain(int argc, _TCHAR* argv[])
{
	TestClass obj;

	std::vector<UserStatistics*> userInfo;
	obj.Fill(userInfo);
	return 0;
}

